
#include "stdafx.h"
#include "Tank.h"
#include <allegro5/allegro.h>

Tank::Tank(const _TankBody & body):
_body( body ) {
  // Bouml preserved body begin 0001F4A2
  // Bouml preserved body end 0001F4A2
}

Tank::~Tank(void ){
  // Bouml preserved body begin 0001F5FB

  // Bouml preserved body end 0001F5FB
}

_TankBody& Tank::GetBody() {
  // Bouml preserved body begin 0001F522
    return _body;
  // Bouml preserved body end 0001F522
}

//Places tank in given position in world.
void Tank::MoveTo(const BaseComponent::point & position) {
  // Bouml preserved body begin 00024DFB
	_position = position;
  // Bouml preserved body end 00024DFB
}

void Tank::Move( float distance ) {
    ALLEGRO_TRANSFORM moveTrans;

    al_identity_transform( &moveTrans );
    al_scale_transform( &moveTrans, 0, distance );
    al_rotate_transform( &moveTrans, _angle );

    float dx = 0, dy = -1;

    al_transform_coordinates( &moveTrans, &dx, &dy );

    _position.x += dx;
    _position.y += dy;
}

//Sets given angle where 0 is top.
void Tank::RotateTo(float angle) {
  // Bouml preserved body begin 00024E7B
	_angle = angle;
	_body->SetAngle( _angle );
  // Bouml preserved body end 00024E7B
}

void Tank::Rotate( float angle ) {
    RotateTo( _angle + angle );
}

//Rotates turret of the tank.
void Tank::RotateTurretTo(char slot, float angle) {
  // Bouml preserved body begin 0002837B
	_body->SetTurretAngle( slot, angle );
  // Bouml preserved body end 0002837B
}

//Draws the tank.
void Tank::Draw() {
  // Bouml preserved body begin 00024EFB
	_body->DrawAt(_position);
  // Bouml preserved body end 00024EFB
}

